<?php

class tarif{
	
	// Class Constructor
	public function __construct(){
		$this->db = new DBClass();
	}
	
	public function getTarif(){
		
		$query = "Select * from tarif";
		$rows = $this->db->getRows($query);
		
		return $rows;
	}

	public function get_data(){
		$query = "select idadmin, username, fullname, email from admin 
			where username='".$_COOKIE['c_usr']."'";

		$rows = $this->db->getRows($query);

		return $rows[0];	
	}
	public function hapusTarif($data){
		
		$query ="DELETE FROM tarif WHERE kode_tarif='".@$data."'";

		$rows = $this->db->getRows($query);

		header('Location: tarif.php');
	}

	public function tambahTarif($data){
		
		$query ="INSERT INTO `tarif` (`kode_tarif`, `kode_rute`, `kode_kelas`, `tarif`) VALUES ('".@$data[3]."', ".@$data[0].", ".@$data[1].", '".@$data[2]."')";

		$this->db->putRows($query);

		header('Location: tarif.php');
	}
	public function Edittarif($data){
		
		$query ="SELECT * FROM tarif WHERE kode_tarif='".@$data."'";
		$rows = $this->db->getRows($query);

		return array_shift($rows);
	}

	public function postEdit($data){
		
		$query ="UPDATE tarif SET kode_rute=".$data[0].", kode_kelas=".$data[1].", tarif='".$data[2]."' WHERE kode_tarif='".$data[3]."'";

		$this->db->putRows($query);
	}
}